package com.efast.dmom.mes.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.EquipSpareInbound;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.entity.EquipSpareInboundEntity;
import com.efast.dmom.mes.entity.base.IModificationFlags;
import com.efast.dmom.mes.service.EquipSpareInboundService;

/**
 * to achieve the sprareInbound to add, delete, update and query
 * 
 * @author wj
 * @date 2020/4/23
 *
 */
@Controller
@RequestMapping(value = "/sprareInbound")
public class EquipSpareInboundController {
	
	@Autowired
	private EquipSpareInboundService equipSpareInboundService;
	
	@RequestMapping(value = "/operateBySpareInBound")
	public @ResponseBody ResultBean operateBySpareInBound(@RequestBody EquipSpareInbound equipSpareInbound) {
		ResultBean resultBean = new ResultBean(true, ' ');
		// Judge to add
		if (equipSpareInbound.getModificationFlag() == IModificationFlags.NEW) {
			return equipSpareInboundService.save(equipSpareInbound);
			// Judge to update
		} else if (equipSpareInbound.getModificationFlag() == IModificationFlags.MODIFIED) {
			return equipSpareInboundService.update(equipSpareInbound);
			// Judge to delete
		} else if (equipSpareInbound.getModificationFlag() == IModificationFlags.DELETED) {
			return equipSpareInboundService.delete(equipSpareInbound);
		}
		return resultBean;
	}
	
	@RequestMapping(value = "/affirmSpareInBound")
	public @ResponseBody ResultBean affirmSpareInBound(@RequestBody List<EquipSpareInboundEntity> spareList) {
		return equipSpareInboundService.affirmSpareInBound(spareList);
	}
	
	@RequestMapping(value = "/operateBySpareInBoundItem")
	public @ResponseBody ResultBean operateBySpareInBoundItem(@RequestBody EquipSpareInbound equipSpareInbound) {
		ResultBean resultBean = new ResultBean(true, ' ');
		// Judge to add
		if (equipSpareInbound.getModificationFlag() == IModificationFlags.NEW) {
			return equipSpareInboundService.saveItem(equipSpareInbound);
			// Judge to update
		} else if (equipSpareInbound.getModificationFlag() == IModificationFlags.MODIFIED) {
			return equipSpareInboundService.updateItem(equipSpareInbound);
			// Judge to delete
		} else if (equipSpareInbound.getModificationFlag() == IModificationFlags.DELETED) {
			return equipSpareInboundService.deleteItem(equipSpareInbound);
		}
		return resultBean;
	}

}
